<?php 
    session_start();
?>

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
                
        <link rel="stylesheet" href="styles/layout.css" type="text/css"/>
        <link rel="stylesheet" href="styles/computer.css" type="text/css"/>
        <script type="text/javascript" src="scripts/computer.js"></script>
        
    </head>
    <body>
        <?php        require 'header.html';
        ?>
        
<div id="container">
  <div class="wrapper">
    <div id="content">
    	<div id="order">         
        <?php
        // put your code here
        if(isset($_SESSION["userID"]) && !strcmp($_SESSION["userType"], "seller")){
        
         echo "Login: ".$_SESSION["userID"]." ".$_SESSION["userType"];
         $productID = $_POST["productID"];
        
         if(strlen($productID) == 0){
            //add a new product
            echo "<h2>Add a new product</h2>";
         }else{
            echo "<h2>Change selected product</h2>";
            $con = mysql_connect("localhost", "zhouzhao", "19831022");
            if(!$con){
                die("could not connect to DB: ".mysql_error());
            }

            mysql_select_db("cloudcom", $con);
            $result = mysql_query("select * from products where productID = $productID");
            $row = mysql_fetch_assoc($result);

            mysql_close($con);
         }
            
        ?>
        
        
            <form method="post" action="commitProduct.php" enctype="multipart/form-data">
            <input type="text" name="productID" style="display: none"
                   <?php
                   if(strlen($productID) != 0){
                       echo "value='".$productID."'";
                   }
                   ?>
                   />
            <p>Category ID: <input type="text" name="categoryID" maxlength="20" class="rightAlign"
                         <?php
                         if(strlen($productID) != 0){
                             echo "value='".$row["categoryID"]."'";
                         }
                         ?>
                         /></p>
            <p>Product Name: <input type="text" name="productName" maxlength="20" class="rightAlign"
                         <?php
                         if(strlen($productID) != 0){
                             echo "value='".$row["productName"]."'";
                         }
                         ?>
                         /></p>
        Product Description: <textarea rows="3" cols="22" name="productDescription" maxlength="50">
                         <?php
                         if(strlen($productID) != 0){
                             echo $row["productDescription"];
                         }
                         ?>
        </textarea><br/>
        <p>Product Image: <input type="file" name="productImage" maxlength="50" class="rightAlign"
                          <?php
                          if(strlen($productID) != 0){
                              echo "value='".$row["productIamge"]."'";
                          }
                          ?>
                          /></p>
        <p>Product Price: <input type="text" name="productPrice" class="rightAlign"
                        <?php
                        if(strlen($productID) != 0){
                            echo "value='".$row["productPrice"]."'";
                        }
                        ?>
                    /></p>
        <input type="submit" name="button" value="Commit Product" class="buttonStyle" onmouseover="changeOn(this)" onmouseout="changeOff(this)"/>
        <input type="submit" name="button" value="Cancel" class="buttonStyle" onmouseover="changeOn(this)" onmouseout="changeOff(this)"/>
        </form>
        
        <?php
        }else{
            require 'login.html';
        }
        ?>
       </div>	
    </div>
    <br class="clear" />
  </div>
</div>
        <?php        require 'tail.html';
        ?>
        
    </body>
</html>
